using Caliburn;
using Caliburn.Castle;
using Caliburn.Composition;
using Caliburn.Configuration;
using Caliburn.Modules;
using Caliburn.PlatformCapabilities;
using Caliburn.Services;
using Caliburn.StateManagement;
using Caliburn.Views;
using Castle.Core;
using Castle.Windsor;
using NServiceBus.Management.EndpointExplorer;
using NServiceBus.Management.Modules;
using NServiceBus.Management.EndpointExplorer.Presenter;
using NServiceBus.Management.Shell.Application;
using NServiceBus.Management.Shell.Presenters;

namespace NServiceBus.Management.Shell
{
    public class CustomConfiguration : ContainerConfiguration
    {
        public CustomConfiguration()
            : this(new WindsorContainer()) { }

        public IWindsorContainer Container
        {
            get { return container; }
        }

        private readonly IWindsorContainer container;

        private CustomConfiguration(WindsorContainer container)
            : base(new WindsorContainerAdapter(container))
        {
            this.container = container;
            container.AddFacility("EventRegistrationFacility", new EventRegistrationFacility());

            container.AddComponentWithLifestyle<IPlatformCapabilities,WindowsCapabilities>(LifestyleType.Singleton);
            container.AddComponentWithLifestyle<IViewManager,ViewManager>(LifestyleType.Singleton);
            container.AddComponentWithLifestyle<IPresenterManager,PresenterManager>(LifestyleType.Singleton);
            container.AddComponentWithLifestyle<ICompositeManager,CompositeManager>(LifestyleType.Singleton);
            container.AddComponentWithLifestyle<IModuleManager, ModuleManager>(LifestyleType.Singleton);
            container.AddComponentWithLifestyle<IShellState, ShellState>(LifestyleType.Singleton);
            container.AddComponentWithLifestyle<IStateSerializer, BinaryStateSerializer>(LifestyleType.Singleton);
            container.AddComponentWithLifestyle<IModuleLocator, RootFolderModuleLocator>(LifestyleType.Singleton);

            container.AddComponentWithLifestyle<ShellPresenter, ShellPresenter>(LifestyleType.Singleton);
            container.AddComponentWithLifestyle<EndpointExplorerPresenter, EndpointExplorerPresenter>(LifestyleType.Singleton);
            //container.AddComponentWithLifestyle<EndpointExplorerModel, EndpointExplorerModel>(LifestyleType.Singleton);
            container.AddComponentWithLifestyle<EndpointExplorerCommandMenuPresenter, EndpointExplorerCommandMenuPresenter>(LifestyleType.Singleton);
        }
    }
}